﻿<Window x:Class="WpfExample.Example"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Example of anonymous class" Height="300" Width="300"
        xmlns:wu="clr-namespace:Monogram.WpfUtils;assembly=WpfUtils"
        xmlns:me="clr-namespace:WpfExample"
        >
    <Grid>

    <wu:DetailsView Name="detailsView1" BorderBrush="Blue" BorderThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center">
      <wu:DetailsView.Resources>

        <wu:VisibilityConverter x:Key="VisibilityConverter" />
        <me:ArithmeticConverter x:Key="ArithmeticConverter" />
        
        <DataTemplate x:Key="DV_HeaderTemplate">
          <ContentControl>
            <ContentControl.Template>
              <ControlTemplate>
                <Grid Name="_main" HorizontalAlignment="Left">
                  <Canvas Name="PART_Background">
                    <Rectangle Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid, AncestorLevel=2}}"
                          Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}"
                          Fill="#CCC" />
                  </Canvas>

                  <TextBlock Text="{Binding Header, StringFormat=\{0\}:}" Margin="2,5,2,2" />

                </Grid>
                <ControlTemplate.Triggers>
                  <DataTrigger Binding="{Binding (Grid.Row), RelativeSource={RelativeSource Mode=Self} , Converter={StaticResource ArithmeticConverter}, ConverterParameter=%2}" Value="0">
                    <Setter TargetName="PART_Background" Property="Visibility" Value="Collapsed" />
                  </DataTrigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </ContentControl.Template>
          </ContentControl>
        </DataTemplate>

        <DataTemplate x:Key="DV_BooleanFieldTemplate">
          <Grid Name="PART_Content" Margin="2" HorizontalAlignment="Left" Height="17" >
            <Image Visibility="{Binding Converter={StaticResource VisibilityConverter}}" Source="/WpfExample;component/yes.png"  />
            <Image Visibility="{Binding Converter={StaticResource VisibilityConverter}, ConverterParameter=nc}" Source="/WpfExample;component/no.png" />
          </Grid>
        </DataTemplate>

      </wu:DetailsView.Resources>
    </wu:DetailsView>
  </Grid>
</Window>
